package com.guchenbo.study.mvc.servlet31.springmvc.servlet;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @Author guchenbo
 * @Date 2019/12/1.
 */
@Configuration
@EnableWebMvc
@ComponentScan(basePackageClasses = ServletConfiguration.class)
public class ServletConfiguration extends WebMvcConfigurerAdapter {

    @Bean
    public HandlerInterceptor springHandlerInterceptor() {
        return new SpringHandlerInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
        registry.addInterceptor(springHandlerInterceptor()).addPathPatterns("/**");
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        super.configureViewResolvers(registry);
        registry.jsp();
    }
}
